home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / mindos11.zip / MRFILE.C < prev    next >
C/C++ Source or Header  |  1991-03-22  |  2KB  |  77 lines

  1. /*  mrfile.c    -- read a Minix file into a buffer */
  2. /*  Copyright 1988,1991 Steven W. Harrold - All rights reserved. */
  3. /*  $Header: MRFILE.C_V 1.2 91/03/19 09:58:14 SWH Exp $ */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    "mfs.h"
  8. #include    "dev.h"
  9.  
  10. READ_BLOCK
  11.  
  12.  
  13. /*==================================================================*/
  14. void read_file(buf, ip, ddata)
  15. void            *buf ;
  16. struct inode    *ip ;
  17. struct devdata  *ddata ;
  18. {
  19.     byte        *bp ;
  20.     ushort      ind_block[BLOCK_SIZE/sizeof(ushort)] ;
  21.     ushort      dbl_block[BLOCK_SIZE/sizeof(ushort)] ;
  22.  
  23.     int         lim = BLOCK_SIZE / sizeof(ushort) ;
  24.  
  25.     int         i, j, k, n ;
  26.     int         blkno ;
  27.  
  28.  
  29.     bp = buf ;
  30.     for (i=0; i<7; i++, bp += BLOCK_SIZE)
  31.     {
  32.         blkno = ip->i_zone[i] ;
  33.         if (blkno == 0)
  34.             break ;
  35.         read_block(bp, blkno, ddata) ;
  36.     }
  37.  
  38.     if (ip->i_ind)
  39.     {
  40.         read_block(ind_block, ip->i_ind, ddata) ;
  41.  
  42.         for (i=0; i<lim; i++, bp += BLOCK_SIZE)
  43.         {
  44.             blkno = ind_block[i] ;
  45.             if (blkno == 0)
  46.                 break ;
  47.             read_block(bp, blkno, ddata) ;
  48.         }
  49.     }
  50.  
  51.     if (ip->i_dbl_ind)
  52.     {
  53.         read_block(dbl_block, ip->i_dbl_ind, ddata) ;
  54.  
  55.         for (i=0; i<lim; i++)
  56.         {
  57.  
  58.             blkno = dbl_block[i] ;
  59.             if (blkno == 0)
  60.                 break ;
  61.             read_block(ind_block, blkno, ddata) ;
  62.  
  63.             for (j=0; j<lim; j++, bp += BLOCK_SIZE)
  64.             {
  65.                 blkno = ind_block[j] ;
  66.                 if (blkno == 0)
  67.                     break ;
  68.                 read_block(bp, blkno, ddata) ;
  69.             }
  70.         }
  71.     }
  72.  
  73. } /* read_file() */
  74.  
  75.  
  76. /*---eof---*/
  77.